import Table from "@/components/Table/Table";
import React, { useMemo } from "react";
import cls from "@/styles/pages/users/Users.module.scss";
import { MonthPredictionI } from "@/models/prediction";
import {
  normalizePredictionData,
  useColumns,
} from "@/feature/PredictionTable/helper";
import { SpecializationI } from "@/models/specialization";

type Props = {
  data: MonthPredictionI[];
  isLoading: boolean;
  specData: SpecializationI[];
};
export const PredictionTable = ({ data, isLoading, specData }: Props) => {
  const dataNormalized = useMemo(() => {
    if (!data) return [];

    return data.map((item) => normalizePredictionData(item)).flat();
  }, [data]);

  const columns = useColumns(specData);

  return (
    <div className={cls.table}>
      <Table
        // @ts-ignore
        data={dataNormalized}
        // @ts-ignore
        columns={columns}
        isLoading={isLoading}
        onRowClick={() => null}
      />
    </div>
  );
};
